package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingGradeMapper;
import com.zzyl.service.NursingGradeService;
import com.zzyl.vo.NursingLevelVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class NursingGradeServiceImpl implements NursingGradeService {
    @Autowired
    private NursingGradeMapper nursingGradeMapper;

    @Override
    public List<NursingLevelVo> findAll() {
        List<NursingLevelVo> nursingLevelVoList = nursingGradeMapper.findAll();
        return nursingLevelVoList;
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        log.info("planid + {}",nursingLevel.getPlanId());
        nursingGradeMapper.add(nursingLevel);
    }

    @Override
    public PageResponse<NursingLevelVo> listPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelVo> page = nursingGradeMapper.listPage(name,status);
        PageResponse<NursingLevelVo> pageResponse = new PageResponse(page);
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }
}
